package com.flipdf2.serialize.ppml.element;

import java.util.ArrayList;
import java.util.List;

import org.jdom.Element;
import org.jdom.Namespace;

import com.flipdf2.serialize.ppml.PPMLException;

public class PPMLSuppliedResources {
	public static final String NAME = "SUPPLIED_RESOURCES";
	
	private List<PPMLSuppliedResource> suppliedResourceList;
	
	public Element toXML(Namespace defaultNamespace) {
		Element root = null;
		if (defaultNamespace != null) {
			root = new Element(NAME, defaultNamespace);
		} else {
			root = new Element(NAME);	
		}
		
		if (suppliedResourceList != null && suppliedResourceList.size() > 0) {
			for (int i = 0, n = suppliedResourceList.size(); i < n; i++) {
				root.addContent(suppliedResourceList.get(i).toXML(defaultNamespace));
			}
		}
		
		return root;
	}

	public void check() throws PPMLException {
		if (suppliedResourceList == null) {
			throw PPMLException.getInstance(PPMLException.REQUIRED_ELEMENT_LOST, "SUPPLIED_RESOURCE");
		}
	}
	
	public List<PPMLSuppliedResource> getSuppliedResourceList() {
		return suppliedResourceList;
	}

	public void setSuppliedResourceList(List<PPMLSuppliedResource> suppliedResourceList) {
		this.suppliedResourceList = suppliedResourceList;
	}
	
	public void addSuppliedResource(PPMLSuppliedResource suppliedResource) {
		if (this.suppliedResourceList == null)
			this.suppliedResourceList = new ArrayList<PPMLSuppliedResource>();
		this.suppliedResourceList.add(suppliedResource);
	}
}
